import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class RealTimeLandscapeController extends GetxController {

  Timer? _timer;

  double screenWidth = 0.0;
  double screenHeight = 0.0;

  @override
  void onInit() {
    super.onInit();

    screenWidth = MediaQuery.of(Get.context!).size.width;
    screenHeight = MediaQuery.of(Get.context!).size.height;

    WidgetsFlutterBinding.ensureInitialized();

    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
    ]);
    _setFullScreen();

    //每秒去检查一下字符串是否有变化,有变化则调用_autoScrollToBottom
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
     /* if (checkFinnalToText != indexViewController!.finalToLanguage.value) {
        checkFinnalToText = indexViewController!.finalToLanguage.value;
        _autoScrollToBottomTo();
      }

      if (checkFinnalFromText != indexViewController!.finalFromLanguage.value) {
        checkFinnalFromText = indexViewController!.finalFromLanguage.value;
        _autoScrollToBottomFrom();
      }*/

    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
    if (_timer != null) {
      _timer!.cancel();
    }


    // 页面退出时恢复系统UI（可选）
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);

    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
  }

  void _setFullScreen() {
    SystemChrome.setEnabledSystemUIMode(
      SystemUiMode.immersiveSticky,
      // 可选：隐藏特定系统栏（根据需求选择）
      overlays: [
        // SystemUiOverlay.top,    // 显示状态栏
        // SystemUiOverlay.bottom, // 显示导航栏
      ],
    );
  }


  void _autoScrollToBottomTo() {
    /*// 使用 animateTo 实现平滑滚动
    firstScrollController.animateTo(
      firstScrollController.position.maxScrollExtent,
      duration: const Duration(milliseconds: 300),
      curve: Curves.easeOut,
    );*/
  }

  void _autoScrollToBottomFrom() {
    // 使用 animateTo 实现平滑滚动
   /* secondScrollController.animateTo(
      secondScrollController.position.maxScrollExtent,
      duration: const Duration(milliseconds: 300),
      curve: Curves.easeOut,
    );*/
  }
}
